package com.gimi.cloud.jimi.app.consumer.service.home.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.gimi.cloud.jimi.app.consumer.feign.HomePageFeignService;
import com.gimi.cloud.jimi.app.consumer.service.home.AuthenticationStepService;
import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.exception.MsgException;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.user.UserDTO;
@Service
public class AuthenticationStepServiceImpl implements AuthenticationStepService {
	private static Logger logger = LoggerFactory.getLogger(AuthenticationStepServiceImpl.class);
	private final HomePageFeignService homePageFeignService;

    public AuthenticationStepServiceImpl(HomePageFeignService homePageFeignService){
        this.homePageFeignService = homePageFeignService;
    }
    
	@Override
	public void getAuthenticationStatus(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		UserDTO DTO = JsonUtil.jsonToBean(requestBody,UserDTO.class);
		if (DTO.getUserId() == null) {
			throw new MsgException(ResponseCodeEnum.FAILURE, "Token中userId为空!");
		}
		Util.sendResponse(homePageFeignService.getAuthenticationStatus(DTO), response);
	}

	@Override
	public void getAuthenticationInfo(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		UserDTO DTO = JsonUtil.jsonToBean(requestBody,UserDTO.class);
		if (DTO.getUserId() == null) {
			throw new MsgException(ResponseCodeEnum.FAILURE, "Token中userId为空!");
		}
		if (DTO.getPage() == null) {
			throw new MsgException(ResponseCodeEnum.FAILURE, "认证步骤不能为空!");
		}
		Util.sendResponse(homePageFeignService.getAuthenticationInfo(DTO), response);
	}

}
